﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TddClientHomework
{
    //story:
    //开发一个时间间隔计算功能，计算两个时间的间隔,单位为秒数
    [TestClass]
    public class UnitTest1
    {
        private TimeSpanCaculator caculator = new TimeSpanCaculator();
        private DateTime preTime = DateTime.Parse("2000-01-01 00:00:00");
        private DateTime nextTime = DateTime.Parse("2000-01-01 01:00:00");

        [TestMethod]
        public void TestCaculateTimeSpanFromSecondToFirst()
        {
            TimeSpan timeSpan = caculator.Caculate(preTime, nextTime);
            Assert.AreEqual(3600, timeSpan.TotalSeconds);
        }


        [TestMethod]
        public void TestCaculateTimeSpanFromFirstToSecond()
        {
            TimeSpan timeSpan = caculator.Caculate(nextTime, preTime);
            Assert.AreEqual(3600, timeSpan.TotalSeconds);
        }
    }




    public class TimeSpanCaculator
    {
        internal TimeSpan Caculate(DateTime first, DateTime second)
        {
            if (second >= first)
            {
                return second - first;
            }
            else
            {
                return first - second;
            }

        }
    }




}
